package javaproject;

import javax.media.j3d.Appearance;
import javax.media.j3d.LineArray;
import javax.media.j3d.Shape3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;

public class GuideLine extends MyPrimitive{
    static final int AXIS_X = 0;
    static final int AXIS_Y = 1;
    static final int AXIS_Z = 2;
    public int axis;

    GuideLine(float length, double[] pos, int axis, Appearance app, float alpha)
    {
	super(pos[0],pos[1],pos[2],app);
	this.axis = axis;
	double[] lineVertices = new double[3*2];
	switch(axis)
        {
            case AXIS_X:
		lineVertices = new double[]
                {
                    x-length/2,y,z,   x+length/2,y,z,
                };
		break;
            case AXIS_Y:
		lineVertices = new double[]
                {
                    x,y-length/2,z,   x,y+length/2,z,
                };
		break;
            case AXIS_Z:
		lineVertices = new double[]
                {
                    x,y,z-length/2,   x,y,z+length/2,
                };
		break;
	}
	LineArray line = new LineArray(2, LineArray.COORDINATES | LineArray.COLOR_4);
        Color3f intrinsicColor = new Color3f();
        app.getColoringAttributes().getColor(intrinsicColor);
        float[] lineColor = new float[4*2];
        for(int i = 0; i < 2; i++)
        {
            lineColor[i*4] = intrinsicColor.get().getRed();
            lineColor[i*4+1] = intrinsicColor.get().getGreen();
            lineColor[i*4+2] = intrinsicColor.get().getBlue();
            lineColor[i*4+3] = alpha;
        }
        line.setCoordinates(0, lineVertices);
        line.setColors(0, lineColor);
        shape = new Shape3D(line, app);
	transG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        transG.addChild(shape);
    }
}
